package com.sdhs.projectschedule.service.impl;

import java.util.List;

import com.sdhs.businessfile.domain.BusinessFile;
import com.sdhs.businessfile.service.IBusinessFileService;
import com.sdhs.common.enums.BusinessTypeEnum;
import com.sdhs.common.utils.DateUtils;
import com.sdhs.common.utils.SecurityUtils;
import com.sdhs.projectstart.domain.ProjectDept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sdhs.projectschedule.mapper.GcProgressConstructionLogMapper;
import com.sdhs.projectschedule.domain.GcProgressConstructionLog;
import com.sdhs.projectschedule.service.IGcProgressConstructionLogService;

/**
 * 项目进度控制--施工日志Service业务层处理
 *
 * @author andong
 * @date 2025-03-10
 */
@Service
public class GcProgressConstructionLogServiceImpl implements IGcProgressConstructionLogService
{
    @Autowired
    private GcProgressConstructionLogMapper gcProgressConstructionLogMapper;

    @Autowired
    private IBusinessFileService businessFileService;
    /**
     * 查询项目进度控制--施工日志
     *
     * @param id 项目进度控制--施工日志主键
     * @return 项目进度控制--施工日志
     */
    @Override
    public GcProgressConstructionLog selectGcProgressConstructionLogById(Long id)
    {
        GcProgressConstructionLog gcProgressConstructionLog = gcProgressConstructionLogMapper.selectGcProgressConstructionLogById(id);
        List<BusinessFile> businessFiles = businessFileService.listByBusinessTypeAndId(BusinessTypeEnum.GC_PROGRESS_CONSTRUCTION_LOG.getCode(), String.valueOf(id));
        gcProgressConstructionLog.setFileList(businessFiles);
        return gcProgressConstructionLog;
    }

    /**
     * 查询项目进度控制--施工日志列表
     *
     * @param gcProgressConstructionLog 项目进度控制--施工日志
     * @return 项目进度控制--施工日志
     */
    @Override
    public List<GcProgressConstructionLog> selectGcProgressConstructionLogList(GcProgressConstructionLog gcProgressConstructionLog)
    {
        return gcProgressConstructionLogMapper.selectGcProgressConstructionLogList(gcProgressConstructionLog);
    }

    /**
     * 新增项目进度控制--施工日志
     *
     * @param gcProgressConstructionLog 项目进度控制--施工日志
     * @return 结果
     */
    @Override
    public int insertGcProgressConstructionLog(GcProgressConstructionLog gcProgressConstructionLog)
    {
        gcProgressConstructionLog.setCreater(SecurityUtils.getUsername());
        gcProgressConstructionLog.setCreateTime(DateUtils.getNowDate());
        int i = gcProgressConstructionLogMapper.insertGcProgressConstructionLog(gcProgressConstructionLog);
        handler(gcProgressConstructionLog.getId(), gcProgressConstructionLog);
        return i;
    }

    /**
     * 修改项目进度控制--施工日志
     *
     * @param gcProgressConstructionLog 项目进度控制--施工日志
     * @return 结果
     */
    @Override
    public int updateGcProgressConstructionLog(GcProgressConstructionLog gcProgressConstructionLog)
    {
        gcProgressConstructionLog.setUpdater(SecurityUtils.getUsername());
        gcProgressConstructionLog.setUpdateTime(DateUtils.getNowDate());
        int i = gcProgressConstructionLogMapper.updateGcProgressConstructionLog(gcProgressConstructionLog);
        handler(gcProgressConstructionLog.getId(), gcProgressConstructionLog);
        return i;
    }

    /**
     * 批量删除项目进度控制--施工日志
     *
     * @param ids 需要删除的项目进度控制--施工日志主键
     * @return 结果
     */
    @Override
    public int deleteGcProgressConstructionLogByIds(Long[] ids)
    {
        return gcProgressConstructionLogMapper.deleteGcProgressConstructionLogByIds(ids);
    }

    /**
     * 删除项目进度控制--施工日志信息
     *
     * @param id 项目进度控制--施工日志主键
     * @return 结果
     */
    @Override
    public int deleteGcProgressConstructionLogById(Long id)
    {
        GcProgressConstructionLog gcProgressConstructionLog = gcProgressConstructionLogMapper.selectGcProgressConstructionLogById(id);
        gcProgressConstructionLog.setIsDelete("1");
        return gcProgressConstructionLogMapper.updateGcProgressConstructionLog(gcProgressConstructionLog);
    }

    /**
     * 保存联合数据
     * 保存合同附件
     */
    public void handler(Long id, GcProgressConstructionLog gcProgressConstructionLog) {
        // 保存合同附件
        businessFileService.saveFileBatch(BusinessTypeEnum.GC_PROGRESS_CONSTRUCTION_LOG.getCode(), String.valueOf(id), gcProgressConstructionLog.getFileList());
    }
}
